package org.szy.plugin.dev.pojo;

import org.szy.core.common.entity.TreeSelect;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 数据字典树形选项
 *
 * @author 孙志阳
 * @date 2023-02-17
 * @since 1.0.0
 **/
public class DevDictTreeOption extends TreeSelect {

    private Integer level;

    public DevDictTreeOption(DevDictTree entity) {
        this.setId(entity.getId() + "");
        this.setSpareId(entity.getCode());
        this.setLabel(entity.getLabel());
        this.setValue(entity.getValue());
        this.setLevel(entity.getLevel());
        if (entity.getChildren() == null || entity.getChildren().isEmpty()) {
            this.setChildren(null);
        } else {
            this.setChildren(entity.getChildren().stream().map(DevDictTreeOption::new).collect(Collectors.toList()));
        }
    }

    public static List<DevDictTreeOption> buildTreeOption(List<DevDictTree> trees) {
        return trees.stream().map(DevDictTreeOption::new).collect(Collectors.toList());
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public Integer getLevel() {
        return level;
    }
}
